package com.ruoyi.business.base.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.business.base.domain.AcceptStandardDetail;
import com.ruoyi.business.base.mapper.AcceptStandardDetailMapper;
import com.ruoyi.business.base.service.IAcceptStandardDetailService;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.SnowIdUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 验收标准详情Service业务层处理
 *
 * @author lcy
 * @date 2024-09-24
 */
@Service
public class AcceptStandardDetailServiceImpl extends ServiceImpl<AcceptStandardDetailMapper, AcceptStandardDetail> implements IAcceptStandardDetailService {

    @Resource
    private AcceptStandardDetailMapper acceptStandardDetailMapper;

    /**
     * 查询验收标准详情
     *
     * @param id 验收标准详情主键
     * @return 验收标准详情
     */
    @Override
    public AcceptStandardDetail selectAcceptStandardDetailById(String id) {
        return acceptStandardDetailMapper.selectAcceptStandardDetailById(id);
    }

    /**
     * 查询验收标准详情列表
     *
     * @param acceptStandardDetail 验收标准详情
     * @return 验收标准详情
     */
    @Override
    public List<AcceptStandardDetail> selectAcceptStandardDetailList(AcceptStandardDetail acceptStandardDetail) {
        return acceptStandardDetailMapper.selectAcceptStandardDetailList(acceptStandardDetail);
    }

    /**
     * 新增验收标准详情
     *
     * @param acceptStandardDetail 验收标准详情
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public Object insertAcceptStandardDetail(AcceptStandardDetail acceptStandardDetail) {
        acceptStandardDetail.setId(SnowIdUtil.genSnowId())
                    .setCreateBy(SecurityUtils.getUsername())
                    .setCreateTime(DateUtils.getNowDate())
                    .setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        acceptStandardDetailMapper.insert(acceptStandardDetail);
        return acceptStandardDetail.getId();
    }

    /**
     * 修改验收标准详情
     *
     * @param acceptStandardDetail 验收标准详情
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int updateAcceptStandardDetail(AcceptStandardDetail acceptStandardDetail) {
        acceptStandardDetail.setUpdateBy(SecurityUtils.getUsername())
                    .setUpdateTime(DateUtils.getNowDate());
        return acceptStandardDetailMapper.updateById(acceptStandardDetail);
    }

    /**
     * 批量删除验收标准详情
     *
     * @param ids 需要删除的验收标准详情主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor =  Exception.class)
    public int deleteAcceptStandardDetailByIds(String[] ids) {
        return acceptStandardDetailMapper.deleteAcceptStandardDetailByIds(ids);
    }

}
